/*
 * @Author: gk 
 *  表建模型
 * @Date: 2018-03-15 14:44:57 
 * @Last Modified by: txy
 * @Last Modified time: 2019-06-24 13:55:22
 */
var dictionaryTreeGrid = null,
	treeGrid = null,
	treeTable = 'tbDictionaryMX';
layui.config({}).use(['element', 'zlConfig', 'zlContext', 'zlSelectEx', 'treeGrid', 'table', 'layer', 'form', 'zlPinYin'], function (exports) {
	var $ = layui.$,
		zlContext = layui.zlContext,
		layer = layui.layer,
		table = layui.table,
		form = layui.form,
		zlPinYin = layui.zlPinYin,
		zlConfig = layui.zlConfig,
		treeGrid = layui.treeGrid,
		statusName = zlConfig.global.result.statusName,
		msgName = zlConfig.global.result.msgName,
		dataName = zlConfig.global.result.dataName,
		OK = zlConfig.global.result.okState,
		tableheight = 250,
		fullheight = resizeFunction(32, 20, tableheight),
		customCurr = 1;

	var fromlayerIndex,
		dictionaryTypes = {},
		isloadsearch = false;
	//同步获取字典类型
	zlContext.asyncGet(
		layui.cache['contentPath'] + '/manager/coredictionary/querydictionarybyid?RWID=439BD47789C94934ACAF625B1F697DFC', null,
		function (result) {
			if (result[statusName] == OK) {
				$(result[dataName]).each(function (index, obj) {
					dictionaryTypes[obj.CODE] = obj.VALUE;
				});
			} else {
				zlContext.errorMsg(result[msgName]);
				return;
			}
		});
	//渲染数据字典列表
	var objTable = table.render({
		height: tableheight,
		elem: '#tbDictionary',
		url: layui.cache['contentPath'] + '/manager/coredictionary/query',
		response: zlConfig.global.gridResponse,
		method: 'post',
		limit: 20,
		limits: [20, 50, 100, 200, 500, 1000],
		page: true,
		sortload: true,
		cols: [
			[ //表头
				{
					type: 'numbers',
					fixed: 'left',
					title: '#'
				}, {
					type: 'checkbox',
					fixed: 'left'
				}, {
					field: 'ZDMX_BIANH',
					title: '编码',
					sort: true,
					width: 250
				}, {
					field: 'ZDMX_MINGC',
					title: '名称',
					sort: true,
					width: 200
				}, {
					field: 'ZDMX_LEIX',
					title: '类型',
					sort: true,
					width: 85,
					templet: function (d) {
						return '<span>' + dictionaryTypes[d.ZDMX_LEIX] + '</span>'
					}
				}, {
					field: 'ZDMX_GUANLBM',
					title: '关联脚本或json',
					sort: true,
					width: 100
				}, {
					field: 'ZDMX_SUOSXT',
					title: '所属系统',
					sort: true,
					width: 100
				}, {
					fixed: 'right',
					field: 'OPTION',
					width: 180,
					title: '操作',
					align: 'center',
					toolbar: '#barDictionary'
				}
			]
		],
		event: {
			onRowdbClick: function (field, row) {
                dictionaryGridAction.viewRow(row);
			},
			onRowClick: function (field, data) {
			if (field == 'OPTION') { return; }
			dictionaryGridAction.currentRow = data;
			layui.event('WM_USERDEF', zlConfig.global.WM_USERDEF.REFRESHDATA_DATAMX, data['RWID']);
			}
		}
	});
	var dictionaryGridAction = {
		currentEditObj: undefined,
		currentRow: undefined,
		directionaryGridedit: function (row, type, arg_readonly) {
			var readonly = arg_readonly && arg_readonly != 0 ? 'disabled' : '';
			var frm = [
				  '<div class="site-block"> <form id ="frmGridDirectionary" class="layui-form"  action="">'
				, '	<div class="layui-form-item layui-hide">'
				, '		<div class="layui-input-block">'
				, '			<input type="text" name="EDITTYPE" class="layui-input">'
				, '			<input type="text" name="RWID" class="layui-input">'
				, '		</div>'
				, '	</div>'
				// , '	<div class="layui-form-item">'
				// , '		<label class="layui-form-label">所属系统</label>'
				// , '		<div class="layui-input-block">'
				// , '			<input type="text" name="ZDMX_SUOSXT" required ' + readonly + '  class="layui-input" maxlength="10"> '
				// , '		</div>'
                // , '	</div>'
                , '	<div class="layui-form-item">'
				, '		<label class="layui-form-label">所属系统:</label>'
				, '		<div class="layui-input-block">'
				, '			<select name="ZDMX_SUOSXT" lay-verify="required" class="select-ext" zlcomponent ' + readonly + ' lay-filter="VERP_SUOSXT"  settings="{titlefield: \'VALUE\', valuefield: \'VALUE\',dataurl:\'' + layui.cache['contentPath'] + '/manager/coredictionary/querydictionarybyid?RWID=1C630186B5FF40E2959E4B09CA2D0BFC\'}"></select>'
				, '		</div>'
				, '	</div>'
				, '	<div class="layui-form-item">'
				, '		<label class="layui-form-label">名称</label>'
				, '		<div class="layui-input-block">'
				, '			<input type="text" name="ZDMX_MINGC" required ' + readonly + ' lay-verify="required" placeholder="请输入名称" class="layui-input" maxlength="85">'
				, '		</div>'
				, '	</div>'
				, '	<div class="layui-form-item">'
				, '		<label class="layui-form-label">编号</label>'
				, '		<div class="layui-input-block">'
				, '			<input type="text" name="ZDMX_BIANH" required ' + readonly + ' lay-verify="required" placeholder="请输入编号" class="layui-input" maxlength="30">'
				, '		</div>'
				, '	</div>'
				, '	<div class="layui-form-item">'
				, '		<label class="layui-form-label">类型</label>'
				, '		<div class="layui-input-block">'
				, '	  		<select name="ZDMX_LEIX" lay-verify="required" ' + readonly + ' placeholder="请选择类型"  zlcomponent class="select-ext" settings="{titlefield: \'VALUE\', valuefield: \'CODE\',dataurl:\'' + layui.cache['contentPath'] + '/manager/coredictionary/querydictionarybyid?RWID=439BD47789C94934ACAF625B1F697DFC\'}">'
				, '	  		</select>'
				, '		</div>'
				, '	</div>'
				, '	<div class="layui-form-item">'
				, '		<label class="layui-form-label">关联脚本或JSON</label>'
				, '		<div class="layui-input-block">'
				, '			<textarea class="layui-textarea" type="text" name="ZDMX_GUANLBM" ' + readonly + ' class="layui-input" maxlength="2000"> </textarea>'
				, '		</div>'
				, '	</div>'
				, '	<div class="layui-form-item' + (readonly == 'disabled' ? ' layui-hide"' : '"') + '>'
				, '		<div class="layui-input-block">'
				, '		  <button class="layui-btn" lay-submit lay-filter="frmGridDirectionary"  ' + readonly + '>保存</button>'
				// , '		  <button type="reset" class="layui-btn layui-btn-primary ' + (type == 'edit' ? 'layui-hide"' : '"') + readonly + '>重置</button>'
				, '		</div>'
				, '	</div>'
				, '</form></div>'
			];
			layer.open({
				type: 1,
				title: readonly == 'disabled' ? '查看' : (type == 'edit' ? '编辑' : '新增'),
				id: 'coreDictionaryLayer',
				area: ['100%', '100%'],
				content: frm.join(''),
				success: function (layero, index) {
					if (type == 'edit') {
						zlContext.autoFill($('#frmGridDirectionary'), row);
						$('#frmGridDirectionary input[name=EDITTYPE]').val('edit');
					} else {
						/**设置隐藏属性*/
						$('#frmGridDirectionary input[name=EDITTYPE]').val('new');
						$('#frmGridDirectionary select[name=ZDMX_LEIX]').val(3);
						$('#frmGridDirectionary input[name=ZDMX_MINGC]').change(function () {
							var v = $('#frmGridDirectionary input[name=ZDMX_MINGC]').val(),
								h = $('#frmGridDirectionary select[name=ZDMX_SUOSXT]').val();
							/**设置数据字典名 */
							var v1 = h == '' ? zlPinYin.C(v) : h + '_' + zlPinYin.C(v);
							if (v1.length > 10) {
								zlContext.warnMsg('设置的编号长度大于10，已为您截取前10位字符，如有需要请自行修改');
								v1 = v1.substring(0, 10);
							}
							$('#frmGridDirectionary input[name=ZDMX_BIANH]').val(v1);
							form.render();
						});
					}
					fromlayerIndex = index;
					form.render();
				},
				cancel: function (index, layero) {
					if (type == 'edit' && readonly != 'disabled') {
						zlContext.isFormDataChange('frmGridDirectionary', dictionaryGridAction.currentEditObj.data, dictionaryGridAction, index)
						return false;
					}
				}
			});
		},
		viewRow: function (row) {
			dictionaryGridAction.directionaryGridedit(row, 'edit', true);
		},
		newRow: function () {
			dictionaryGridAction.directionaryGridedit(null, 'new');
		},
		editRow: function (row) {
			dictionaryGridAction.directionaryGridedit(row, 'edit');
		},
		deleteRows: function (rows) {
			if (rows.length == 0) {
				zlContext.warnMsg('请选择需要删除的数据字典');
				return;
			}
			zlContext.confirm('询问', '删除数据字典可能会影响系统正常运行，是否确认删除?', function (index) {
				var ids = "";
				for (var i = 0; i < rows.length; i++) {
					ids += rows[i]['RWID'] + ",";
				}
				ids = ids.substr(0, ids.length - 1);
				//提交删除
				zlContext.deletePost(layui.cache['contentPath'] + '/manager/coredictionary/remove', {
					id: ids
				}, function (result) {
					if (result[statusName] == OK) {
						if (dictionaryGridAction.currentEditObj != undefined) {
							dictionaryGridAction.currentEditObj.del();
							dictionaryGridAction.currentEditObj = undefined;
						} else {
							dictionaryGridAction.refreshGrid('del', null);
						}
						var $pageBox = $('#tbDictionary').siblings('div.layui-table-view').find('span.layui-laypage-count'),
							currCount = $pageBox.html().replace(/[^0-9]/ig, ""),
							afterDelNum = parseInt(currCount) - rows.length + '';
						$pageBox.html('共 ' + afterDelNum + ' 条');
						zlContext.successMsg('删除成功');
					} else {
						zlContext.errorMsg(result[msgName]);
					}
				});
				layer.close(index);
			});
		},
		search: function () {
			var param = {}
			if ($('#edtSeacherValue').val().length > 0) {
				param['SEARCHVALUE'] = $('#edtSeacherValue').val();
				isloadsearch = true;
			} else {
				param = {};
			}
			layui.event('WM_USERDEF',
				zlConfig.global.WM_USERDEF.REFRESHDATA_DATA, param);
		},
		sumbit: function (fields) {
			var editType = $('#frmGridDirectionary input[name=EDITTYPE]').val();
			if (editType == 'new') {
				zlContext.put(layui.cache['contentPath'] + '/manager/coredictionary/add', fields, function (result) {
					if (result[statusName] == OK) {
						dictionaryGridAction.refreshGrid(editType, result[dataName]);
						layer.close(fromlayerIndex);
						zlContext.successMsg('保存成功');
						return true;
					} else {
						zlContext.errorMsg(result[msgName]);
					}
				});
			}
			if (editType == 'edit') {
				zlContext.post(layui.cache['contentPath'] + '/manager/coredictionary/modify', fields, function (result) {
					if (result[statusName] == OK) {
						dictionaryGridAction.refreshGrid(editType, fields);
						layer.close(fromlayerIndex);
						zlContext.successMsg('保存成功');
						return true;
					} else {
						zlContext.errorMsg(result[msgName]);
					}
				});
			}
			return false;
		},
		refreshGrid: function (type, row) {
			/**刷新行 */
			if (type == 'edit' && dictionaryGridAction.currentEditObj) {
				dictionaryGridAction.currentEditObj.update(row);
			} else if (type == 'new') {
				// objTable.reload('tbDictionary');
				$('#edtSeacherValue').val('');
				dictionaryGridAction.search();
			} else if (type == 'del') {
				table.deleteCheckRows('tbDictionary');
			}
        }
	}
	$('#btnDictionaryNew').on('click', function () {
		dictionaryGridAction.newRow();
	});
	$('#btnDictionaryDelete').on('click', function () {
		var checkStatus = table.checkStatus('tbDictionary'),
			rows = checkStatus.data;
		dictionaryGridAction.deleteRows(rows);
	});
	$('#btnSeacher').on('click', function () {
		customCurr = 1;
		dictionaryGridAction.search();
	});
	$('#edtSeacherValue').on('keyup', function (event) {
		var keyCode = event.keyCode;
			customCurr = 1;
		if (keyCode == 13) {
			dictionaryGridAction.search();
		}
		if ((keyCode == '46' || keyCode == '8' || (event.ctrlKey && keyCode == '86')) && $(this).val() == '' && isloadsearch) {
			$('#btnSeacher').trigger('click');
			isloadsearch = false;
		}
	});

	table.on('tool(tbDictionary)', function (obj) {
		var row = obj.data, //获得当前行数据
			layEvent = obj.event; //获得当前行 tr 的DOM对象
		if (layEvent === 'detail') { //查看
			dictionaryGridAction.viewRow(row)
		} else if (layEvent === 'del') { //删除
			dictionaryGridAction.currentEditObj = obj;
			dictionaryGridAction.deleteRows([row]);
		} else if (layEvent === 'edit') { //编辑
			dictionaryGridAction.currentEditObj = obj;
			dictionaryGridAction.editRow(row);
		}
    });
    
	//提交
	form.on('submit(frmGridDirectionary)', function (frm) {
		if ($(frm.elem).hasClass('getField')) {
			dictionaryGridAction.newFields = frm.field;
			return false;
		}
		return dictionaryGridAction.sumbit(frm.field);
	});

	//渲染字典项列表
	dictionaryTreeGrid = treeGrid.render({
		id: treeTable,
		elem: '#' + treeTable,
		height: fullheight,
		response: zlConfig.global.gridResponse,
		limit: 10000,
		method: 'post',
		idField: 'RWID',
		treeId: 'RWID', //树形id字段名称
		treeUpId: 'SYS_PARENTID', //树形父id字段名称
		treeShowName: 'ZDZ_MINGC', //以树形式显示的字
		isOpenDefault: false,
		isAsynchronous:true, // 启用懒加载方式
		parentid:'SYS_PARENTID',//懒加载需要获取点击时传给后端入参的名字
		chkboxType:{ "Y": "", "N": "" },
		cols: [
			[ //表头
				{
					type: 'numbers',
					title: '#'
				}, {
					type: 'checkbox',
				}, {
					field: 'ZDZ_MINGC',
					title: '名称',
					width: 200
				}, {
					field: 'ZDZ_BIANH',
					title: '编号',
					width: 200
				}, {
					field: 'ZDZ_ZIDZ',
					title: '字典项值',
					width: 100
				}, {
					field: 'ZDZ_YANGS',
					title: '样式',
					width: 80
				}, {
					field: 'SYS_SORT',
					title: '排序',
					width: 100
				}, {
					field: 'ZDZ_SHIFQY',
					title: '启用',
					width: 80,
					templet: function (d) {
						return '<input type="checkbox" name="ZDZ_SHIFQY" value="' + d.ZDZ_SHIFQY + '" disabled lay-skin="primary" ' + (d.ZDZ_SHIFQY ? "checked" : "") + '>'
					}
				}, {
					type: '',
					fixed: 'right',
					width: 180,
					title: '操作',
					align: 'center',
					toolbar: '#barDictionaryMX'
				}
			]
		]
	});

	var dictionaryMXGridAction = {
		currentEditObj: undefined,
		Gridedit: function (dictItem, row, type, arg_readonly) {
			var readonly = arg_readonly && arg_readonly != 0 ? 'disabled' : '';
			var frm = [
				  '<div class="site-block"> <form id ="frmGridDictionaryMX" class="layui-form"  action="">'
				, '	<div class="layui-form-item layui-hide">'
				, '		<div class="layui-input-block">'
				, '			<input type="text" name="EDITTYPE" class="layui-input">'
				, '			<input type="text" name="RWID" class="layui-input">'
				, '			<input type="text" name="ZDZ_DICTIONARYID" class="layui-input">'
				, '			<input type="text" name="SYS_PARENTID" class="layui-input">'
				, '		</div>', '	</div>', '	<div class="layui-form-item">'
				, '			<label class="layui-form-label">名称</label>'
				, '			<div class="layui-input-block">'
				, '				<input type="text" name="ZDZ_MINGC" required ' + readonly + ' lay-verify="required" placeholder="请输入名称" class="layui-input" maxlength="85">'
				, '			</div>'
				, '	</div>'
				, '	<div class="layui-form-item">'
				, '			<label class="layui-form-label">编号</label>'
				, '			<div class="layui-input-block">'
				, '				<input type="text" name="ZDZ_BIANH" ' + readonly + ' placeholder="请输入编号" class="layui-input" maxlength="10">'
				, '			</div>'
				, '	</div>'
				, '	<div class="layui-form-item">'
				, '			<label class="layui-form-label">字典项值</label>'
				, '			<div class="layui-input-block">'
				, '				<textarea  name="ZDZ_ZIDZ" required class="layui-textarea" placeholder="请输入字典项值" ' + readonly + ' maxlength="666"></textarea>'
				, '			</div>'
				, '	</div>'
				, '	<div class="layui-form-item">'
				, '			<label class="layui-form-label">样式</label>'
				, '			<div class="layui-input-block">'
				, '				<textarea placeholder="请输入内容" name="ZDZ_YANGS" class="layui-textarea" ' + readonly + ' maxlength = "85"></textarea>'
				, '			</div>'
				, '	</div>'
				, '	<div class="layui-form-item">'
				, '			<label class="layui-form-label">排序</label>'
				, '			<div class="layui-input-block">'
				, '				<input type="text" name="SYS_SORT" ' + readonly + ' placeholder="请输入排序号" class="layui-input" lay-verify="numberInt" maxlength = "7">'
				, '			</div>'
				, '	</div>'
				, '	<div class="layui-form-item">'
				, '			<label class="layui-form-label">启用</label>'
				, '			<div class="layui-input-block">'
				, '				<input type="checkbox"  name="ZDZ_SHIFQY" valueformat="1|0" lay-skin="primary" ' + readonly + '>'
                , '			</div>'
                , '	</div>'
                , '	<div class="layui-form-item' + (readonly == 'disabled' ? ' layui-hide"' : '"') + '>'
				, '		<div class="layui-input-block">'
				, '		  <button class="layui-btn" lay-submit lay-filter="frmGridDictionaryMX">保存</button>'
				// , '		  <button type="reset" class="layui-btn layui-btn-primary ' + (type == 'edit' ? 'layui-hide"' : '"') + readonly + '>重置</button>'
				, '		</div>'
				, '	</div>'
				, '</form></div>'
			];
			layer.open({
				type: 1,
				title: readonly == 'disabled' ? '查看' : (type == 'edit' ? '编辑' : '新增'),
				id: 'coreDictionaryAuthLayer',
				area: ['100%', '100%'],
				content: frm.join(''),
				success: function (layero, index) {
					if (type == 'edit') {
						zlContext.autoFill($('#frmGridDictionaryMX'), row);
						$('#frmGridDictionaryMX input[name=EDITTYPE]').val('edit');
						$('#frmGridDictionaryMX input[name=RWID]').val(row['RWID']);
					} else {
						$('#frmGridDictionaryMX input[name=ZDZ_SHIFQY]').prop("checked", true);
						form.render();
						/**设置隐藏属性*/
						$('#frmGridDictionaryMX input[name=EDITTYPE]').val('new');
						$('#frmGridDictionaryMX input[name=ZDZ_DICTIONARYID]').val(dictItem['RWID']);
						//如果是树形则添加父节点id
						if(1 == dictItem['ZDMX_LEIX']){
							var selRow = treeGrid.checkStatus('tbDictionaryMX').data;
							if(selRow && 1 == selRow.length){
								$('#frmGridDictionaryMX input[name=SYS_PARENTID]').val(selRow[0]['RWID']);
							}
						}
					}
					if (readonly == 'disabled') {
						$('[placeholder][id!="edtSeacherValue"]').attr('placeholder', '');
					}
					fromlayerIndex = index;
				},
				cancel: function (index, layero) {
					if (type == 'edit' && readonly != 'disabled') {
						zlContext.isFormDataChange('frmGridDictionaryMX', dictionaryMXGridAction.currentEditObj.data, dictionaryMXGridAction, index)
						return false;
					}
				}
			});
		},
		viewRow: function (row) {
			dictionaryMXGridAction.Gridedit(null, row, 'edit', true);
		},
		newRow: function () {
			if (!dictionaryGridAction.currentRow) {
				zlContext.warnMsg('请选择上方表格中的目录项');
				return;
			}
			//判断是否为树形
			if(1 == dictionaryGridAction.currentRow['ZDMX_LEIX']){
				//获取明细选择个数
				var checkStatus = treeGrid.checkStatus('tbDictionaryMX')
				, rows = checkStatus.data;
				if (rows.length > 1) {
					zlContext.warnMsg("不能同时在两个树形节点下增加子节点！");
					return;
				}
			}
			dictionaryMXGridAction.Gridedit(dictionaryGridAction.currentRow, null, 'new');
		},
		editRow: function (row) {
			dictionaryMXGridAction.Gridedit(null, row, 'edit');
		},
		deleteRows: function (rows) {
			if (rows.length == 0) {
				zlContext.warnMsg('请选择需要删除的字典项');
				return;
			}
			for(var i = 0; i < rows.length;i++){
				if(rows[i].children && rows[i].children.length > 0){
					zlContext.warnMsg('字典项【' + rows[i].ZDZ_MINGC + "】下包含子节点，请先删除子节点");
					return;
				}
				if(rows[i].ZDZ_SHIFQY == '1'){
					zlContext.warnMsg('字典项【' + rows[i].ZDZ_MINGC + "】正在启用，无法删除");
					return;
				}
			}
			zlContext.confirm('询问', '删除字典项可能会影响系统正常运行，是否确认要删除?', function (index) {
				var ids = "";
				for (var i = 0; i < rows.length; i++) {
					ids += rows[i]['RWID'] + ",";
				}
				ids = ids.substr(0, ids.length - 1);
				//提交删除
				zlContext.deletePost(layui.cache['contentPath'] + '/manager/coredictionary/removemx', {
					id: ids
				}, function (result) {
					if (result[statusName] == OK) {
						if (rows[0].del) {
							dictionaryMXGridAction.currentEditObj.del();
							dictionaryMXGridAction.currentEditObj = undefined;
						} else {
							dictionaryMXGridAction.refreshGrid('del', rows);
						}
					} else {
						zlContext.errorMsg(result[msgName]);
					}
				});
				layer.close(index);
			});
		},
		sumbit: function (indexs) {
			var editType = $('#frmGridDictionaryMX input[name=EDITTYPE]').val();
			if (editType == 'new') {
				zlContext.put(layui.cache['contentPath'] + '/manager/coredictionary/addmx', indexs, function (result) {
					if (result[statusName] == OK) {
						dictionaryMXGridAction.refreshGrid(editType, result[dataName]);
						layer.close(fromlayerIndex);
						return true;
					} else {
						zlContext.errorMsg(result[msgName]);
					}
				});
			}
			if (editType == 'edit') {
				zlContext.post(layui.cache['contentPath'] + '/manager/coredictionary/modifymx', indexs, function (result) {
					if (result[statusName] == OK) {
						dictionaryMXGridAction.refreshGrid(editType, indexs);
						layer.close(fromlayerIndex);
						return true;
					} else {
						zlContext.errorMsg(result[msgName]);
					}
				});
			}
			return false;
		},
		refreshGrid: function (type, row) {
			treeGrid.reload(treeTable);
			/**刷新行 */
			// if (type == 'edit' && dictionaryMXGridAction.currentEditObj) {
			// 	dictionaryMXGridAction.currentEditObj.update(row);
			// }
			// else if (type == 'new') {
			// 	treeGrid.reload(treeTable);
			// }else if (type == 'del') {
			// 	treeGrid.reload(treeTable);
			// }
			// form.render();
        },
        hidebutton:function(){
            var isShow=true;
            if(dictionaryGridAction.currentRow&&dictionaryGridAction.currentRow.ZDMX_LEIX==3){
                isShow=false;   
            }
            if(isShow){
                $("#btnDictionaryMXNew").show();
                $("#btnDictionaryMXDelete").show();
                $(".mxbtn").show();
            }else{
                $("#btnDictionaryMXNew").hide();
                $("#btnDictionaryMXDelete").hide();
                $(".mxbtn").hide();
            }    
        }
	}
	$('#btnDictionaryMXNew').on('click', function () {
		dictionaryMXGridAction.newRow();
	});
	$('#btnDictionaryMXDelete').on('click', function () {
		var checkStatus = treeGrid.checkStatus('tbDictionaryMX'),
			rows = checkStatus.data;
		dictionaryMXGridAction.deleteRows(rows);
	});
	treeGrid.on('tool(tbDictionaryMX)', function (obj) {
		var row = obj.data; //获得当前行数据
		var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
		if (layEvent === 'detail') { //查看
			dictionaryMXGridAction.viewRow(row)
		} else if (layEvent === 'del') { //删除
			dictionaryMXGridAction.currentEditObj = obj;
			dictionaryMXGridAction.deleteRows([row]);
		} else if (layEvent === 'edit') { //编辑
			dictionaryMXGridAction.currentEditObj = obj;
			dictionaryMXGridAction.editRow(row);
		}
	});
	//提交
	form.on('submit(frmGridDictionaryMX)', function (frm) {
		if ($(frm.elem).hasClass('getField')) {
			dictionaryMXGridAction.newFields = frm.field;
			return false;
		}
		return dictionaryMXGridAction.sumbit(frm.field);
	});
	//监听刷新主表的事件
	layui.event('WM_USERDEF', zlConfig.global.WM_USERDEF.REFRESHDATA_DATA, null, function (param) {
		var loadGridData = function (tableId, url, param) {
			objTable.reload({
				// url: url
				// , method: 'post'
				height: tableheight,
				// , page: true
				where: param,
				page:{
					curr:customCurr
				},
				done: function (res, curr, count) {
					customCurr = curr
				}
			});
		}
		loadGridData('tbDictionary', layui.cache['contentPath'] + '/manager/coredictionary/query', param);
		layui.event('WM_USERDEF', zlConfig.global.WM_USERDEF.REFRESHDATA_DATAMX, '-');
	});
	//监听刷新从表的事件
	layui.event('WM_USERDEF', zlConfig.global.WM_USERDEF.REFRESHDATA_DATAMX, null, function (param) {
		var index = layer.msg('数据查询中，请稍候...', {
			icon: 16,
			time: false,
			shade: 0.1
		});
		var loadGridData = function (id, url, param) {
			treeGrid.reload(treeTable, {
				url: url,
				method: 'post',
				where: param,
				done: function (res, curr, count) {
                    layer.close(index);
                    dictionaryMXGridAction.hidebutton();
				}
			});
        }
        
		loadGridData('tbDictionaryMX', layui.cache['contentPath'] + '/manager/coredictionary/querymxtree', {
			ZDZ_DICTIONARYID: param
		});
	});
	layui.event('WM_USERDEF', zlConfig.global.WM_USERDEF.REFRESHDATA_DATAMX, null)
	// 窗口大小变化事件，filldeff用于求".docking-fill"元素的高差值，condeff用于求".zl-container"的高差值
	function resizeFunction(filldeff, condeff, tableheight) {
		var windowH = $(window).height(),
			// zlcontainerH,
			topzltoolbar = $(".docking-top .zl-toolbar"),
			bottomzltoolbar = $(".docking-bottom .zl-toolbar"),
			dockingtopmb = parseFloat($(".docking-top").css("margin-bottom")),
			topzltoolbarH = topzltoolbar.height() + parseFloat(topzltoolbar.css("margin-bottom")),
			bottomzltoolbarH = bottomzltoolbar.height() + parseFloat(bottomzltoolbar.css("margin-bottom"));
		$(".docking-bottom").height(windowH - dockingtopmb - topzltoolbarH - tableheight - filldeff);
		$(".docking-bottom .zl-container").height($(".docking-bottom").height() - condeff - bottomzltoolbarH);
		return $(".docking-bottom").height() - condeff - bottomzltoolbarH;
	}
	
	$(window).on('resize', function () {
		resizeFunction(32, 20, tableheight);
		treeGrid.reload(treeTable);
	}).resize();
});